<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


//****** 20141126 by liub 个人账户中心
class Acenter extends CI_Controller {
	function __construct(){
		parent::__construct();
		
	}
	
	
	// 首页
	function index(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			// 账户资金，提现和充值
	
			// 充值记录查询，页面制定
			
			// 提现记录查询，页面制定
			
			// 资金明细查询，页面制定
			
			// 投资记录查询，页面制定
			$data['tab'] = 2;
			$this->load->view('mobile/accountmsg',$data);
			
		}else{
			header('Location: /mobile/login/index/index.html');
		}
	}
	
	// 充值
	function recharge(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			if (time()>=strtotime('2014-11-26')){
				$ret['msg'] = '线下充值正在开通中，请前往一点投官网使用线上充值';
				$ret['url_title'] = '返回';
				$ret['url_next']="/mobile/acenter.html";//****** by liub 20141126 返回到个人账户中心
				$this->load->view('mobile/msg',$ret);
			}else{
				$this->load->model('User_model', 'user');
				$user = $this->user->get_by_uid($user['user_id']);
				$data['tab'] = 2;
				$this->load->view('mobile/recharge',$user);
			}
		}else{
			header('Location: /mobile/login/index/index.html');
		}
	}
	
	// 提现
	function cash(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			$this->load->model('User_model', 'user');
			$this->load->model('Account_bank_model', 'bank');
			$this->load->model('Account_model', 'account');
			$this->load->model('Accountlog_model', 'accountlog');
			
			$data['user'] = $this->user->get_by_uid($user['user_id']);
			$data['bank_list'] = $this->bank->arrays('var_account_bank');
			$data['account'] = $this->account->get_account($user['user_id']);
			$data['bank'] = $this->bank->get_by_uid($user['user_id']);
			$data['cash_fee'] = $this->accountlog->cash_fee($user['user_id']);
			$data['cash_fee'] = min($data['cash_fee'],$data['account']['use_money']);
			
			if($data['user']['real_status'] != 1){
				$ret['msg'] = '尚未实名认证';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
				return;
			}elseif (!isset($data['bank']['user_id'])){
				$ret['msg'] = '尚未填写银行账户';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
				return;
			}
			$data['tab'] = 2;
			$this->load->view('mobile/cash',$data);
		}else{
			header('Location: /mobile/login/index/index.html');
		}
	}
	
	// 提交提现
	function submit(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			$this->load->model('User_model', 'user');
			$this->load->model('Account_bank_model', 'bank');
			$this->load->model('Account_model', 'account');
			$this->load->model('Accountlog_model', 'accountlog');
			
			$data['user'] = $this->user->get_by_uid($user['user_id']);
			$data['bank_list'] = $this->bank->arrays('var_account_bank');
			$data['account'] = $this->account->get_account($user['user_id']);
			$data['bank'] = $this->bank->get_by_uid($user['user_id']);
			$data['cash_fee'] = $this->accountlog->cash_fee($user['user_id']);
			$data['cash_fee'] = min($data['cash_fee'],$data['account']['use_money']);
			
			if($data['user']['real_status'] != 1){
				$ret['msg'] = '尚未实名认证';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
			}elseif($data['user']['paypassword'] == ''){
				$ret['msg'] = '尚未设置交易密码';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
			}elseif (!isset($data['bank']['user_id'])){
				$ret['msg'] = '尚未填写银行账户';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
			}else{
				$paypwd = $this->input->post('paypwd');
				$money  = $this->input->post('money');
				if(!is_numeric($money)){
					$ret['msg'] = '无效的金额';
					$ret['url_title'] = '返回';
					$ret['url_next']="/mobile/cash.html";
					$this->load->view('mobile/msg',$ret);
					return 0;
				}else{
					$money = round($money,2);
					if($money < 100 || $money > 1000000){
						$ret['msg'] = '单笔提现金额超出范围(100-1000000)';
						$ret['url_title'] = '返回';
						$ret['url_next']="/mobile/cash.html";
						$this->load->view('mobile/msg',$ret);
					}elseif(md5(md5($paypwd)) != $data['user']['paypassword']){
						$ret['msg'] = '交易密码不正确';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}elseif ($data['account']['use_money'] < $money){
						$ret['msg'] = '可用余额不足';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}else{
						
						$expMoney = $data['account']['exp_money_12']+$data['account']['exp_money_24'];
						if ($data['account']['use_money']-$money<$expMoney){
							$ret['msg'] = '体验金不能用于提现';
							$ret['url_title'] = '返回';
							$ret['url_next']="/zhs_mobile/cash.html";
							$this->load->view('zhs_mobile/msg',$ret);
						}
						$account_result =  $data['account'];
						
						$time = time();
						$ip = $this->input->ip_address();
						$fee = 0;
						
						$use_money = $account_result['use_money'] - $money;
						$use_money = round($use_money,2);
						//15天之内的充值金额提现需要收手续费 0.01收取
						$dont_moeny = $this->accountlog->donnot_mention_15($user['user_id']);
						$dont_moeny = round($dont_moeny,2);
						//提现:15天之内的金额需要收手续费，按千分之五
						if($data['user']['is_loan']==0 && $use_money < $dont_moeny){
							$cha = $dont_moeny-$use_money;
							$cha = min($cha,$money);
							$fee = sprintf("%.2f", ($cha*0.005*100)/100);
						}
						$this->db->trans_strict(FALSE);
						$this->db->trans_begin();//事务开始
						//添加提现表记录
						$setArr = array(
							'user_id' => $user['user_id'],
							'fstatus' => '0',
							'account' => $data['bank']['account'],
							'bank' => $data['bank']['bank'],
							'branch' => $data['bank']['branch'],
							'province' => $data['bank']['province'],
							'city' => $data['bank']['city'],
							'total' => $money,
							'credited' => $money - $fee,
							'fee' =>$fee,
							'add_time' => $time,
							'addip' => $ip
						);
						$this->load->model('Accountcash_model', 'cash');
						$ret = $this->cash->add($setArr);
						if($ret > 0){
							$log = array(
								'user_id' => $user['user_id'],
								'ftype' => CASH_FROST,
								'money' => $money,
								'total' => $data['account']['total'],
								'use_money' => $data['account']['use_money']-$money,
								'no_use_money' => $data['account']['no_use_money']+$money,
								'collection' => $data['account']['collection'],
								'red_money' => $data['account']['red_money'],
								'to_user' => 0,
								'add_time' => $time,
								'addip' => $ip,
								'remark' => "提现冻结"
							);
							$ret = $this->account->addlog($log);
						}
						if($this->db->trans_status() === TRUE){
							$this->db->trans_commit();
							$ret1['msg'] = '提现申请已提交，请等待审核';
							$ret1['url_title'] = '返回';
							$ret1['url_next']="/mobile/ucenter.html";
							$this->load->view('mobile/msg',$ret1);
						}else{
							$this->db->trans_rollback();
							$ret1['msg'] = '提现失败，请重试';
							$ret1['url_title'] = '返回';
							$ret1['url_next']="/mobile/cash/index.html";
							$this->load->view('mobile/msg',$ret1);
						}
					}
				}
			}
		}else{
			header('Location: /mobile/login/index/index.html');
		}
	}

	
	// 充值记录查询
	function queryrecahrge($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountrecharge_model', 'recharge');
		$this->load->model('Payment_model', 'payment');
		//充值统计
		$resData = $this->recharge->get_accountrecharge_list($parms);
		$data['recharge_list'] = $resData['accountrecharge_list'];
		$recharge_status 		= $this->recharge->arrays("account_recharge_status");
		$payment_list 			= $this->payment->get_list();
		$recharge_list = array();
		foreach ($data['recharge_list'] as $recharge){//TODO 信息可填充
			
			$recharge['payment'] 		= isset($payment_list[$recharge['payment']]) ? $payment_list[$recharge['payment']]['name'] : '线下充值';
			$recharge['money'] 			= number_format($recharge['money'],2);
			$recharge['add_time'] 		= date('Y-m-d H:i',$recharge['add_time']);
			$recharge['fstatus_text'] 	= $recharge_status[$recharge['fstatus']];
			$recharge_list[] = $recharge;
		}
		$data['recharge_list'] = $recharge_list;
		$data['page'] = count($data['recharge_list']);
		//echo count($data['recharge_list']);exit;
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/cz', $data);
	}
	
	// 提现记录查询
	function querycash($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		/////////////提现记录///////////////
		$this->load->model('Accountcash_model', 'cash');
		$resData = $this->cash->get_accountcash_list($parms);
		$cash_list = $resData['accountcash_list'];
		$cash_status 	= $this->cash->arrays("account_cash_status");
		$cash_lsit1 = array();
		foreach($cash_list as $cash){//TODO 信息可填充
			$cash['total'] 	= number_format($cash['total'],2);
			$cash['fee'] 	= number_format($cash['fee'],2);
			$cash['add_time'] = date('Y-m-d H:i', $cash['add_time']);
			$cash['fstatus_text'] = $cash_status[$cash['fstatus']];
			$cash_lsit1[] = $cash;
		}
		$data['cash_list'] = $cash_lsit1;
		
		$data['page'] = count($data['cash_list']);
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/tx', $data);
	}
	
		
	// 投资明细查询
	function  querydetails($page=0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		/////////////投资明细记录///////////////
		$this->load->model('Borrow_model', 'borrow_tender');
		$resData = $this->borrow_tender->borrow_tender_user_list($parms);
		$invest_list = $resData['tender_list'];
		$borrow_status 	= $this->borrow_tender->arrays("borrow_tender_status");
		$invest_lsit1 = array();
		foreach($invest_list as $invest){	//TODO 信息可选填充
			$invest['account'] 	= number_format($invest['account'],2);
			$invest['fee'] 	= number_format($invest['fee'],2);
			$invest['add_time'] = date('Y-m-d H:i', $invest['add_time']);
			$invest['fstatus_text'] = $borrow_status[$invest['tender_fstatus']];
			$invest['borrow_id'] = $invest['borrow_id'];
			$invest_lsit1[] = $invest;
		}
		$data['invest_list'] = $invest_lsit1;
		$data['page'] = count($data['invest_list']);
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/tz', $data);
	}
	
	// 资金明细查询
	function queryinvest($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		////////////////资金使用记录////////////////////////
		$this->load->model('Accountlog_model', 'accountlog');
		$resData = $this->accountlog->get_accountlog_list($parms);
		$account_log_list = $resData['accountlog_list'];
		$log_type 			= $this->accountlog->arrays("account_type");
		$account_log_list1 = array();
		foreach($account_log_list as $account_log){//TODO 信息可填充
			$account_log['ftype'] = $log_type[$account_log['ftype']];
			$invest['money'] 	= number_format($account_log['money'],2);
			$account_log['add_time'] = date('Y-m-d H:i', $account_log['add_time']);
			$account_log_list1[] = $account_log;
		}
		$data['account_log_list'] = $account_log_list1;
		$data['page'] = count($data['account_log_list']);
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/zj', $data);
	}
	// 回款明细查询
	function queryreturn($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['order'] = 4;
		$parms['select'] = 1;
		$parms['where']['user_id'] = $user['user_id'];
		////////////////资金回款记录////////////////////////
		$this->load->model('Borrow_model', 'collectionlog');
		$resData = $this->collectionlog->get_user_collection($parms);
		$collection_log_list = $resData['collection_list'];
		//$log_type 			= $this->collectionlog->arrays("account_type");
		$collection_log_list1 = array();
		foreach($collection_log_list as $collection_log){//TODO 信息可填充
			$collection_log1['borrow_id'] = $collection_log['borrow_id'];
			$collection_log1['fstatus']=$collection_log['fstatus'];
			$collection_log1['repay_account'] 	= number_format($collection_log['repay_account'],2);
			$collection_log1['repay_yesaccount'] 	= number_format($collection_log['repay_yesaccount'],2);
			$collection_log1['repay_yestime'] = date('Y-m-d H:i', $collection_log['repay_yestime']);
			$collection_log1['repay_time'] = date('Y-m-d H:i', $collection_log['repay_time']);
			$collection_log_list1[] = $collection_log1;
		}
		$data['collection_log_list'] = $collection_log_list1;
		$data['page'] = count($data['collection_log_list']);
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/hk', $data);
	}

	
	
	
   /**
	 * 更多提现
	 * @param int $page
	 */
	function cashed_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 4;
		$parms['where']['user_id'] = $user['user_id'];
		//充值统计
		$this->load->model('Accountcash_model', 'cash');
		$resData = $this->cash->get_accountcash_list($parms);
		$cash_list = $resData['accountcash_list'];
		$cash_status 	= $this->cash->arrays("account_cash_status");
		$cash_lsit1 = array();
		foreach($cash_list as $cash){//TODO 信息可选填充
			$cash['total'] 	= number_format($cash['total'],2);
			$cash['fee'] 	= number_format($cash['fee'],2);
			$cash['add_time'] = date('Y-m-d H:i', $cash['add_time']);
			$cash['fstatus_text'] = $cash_status[$cash['fstatus']];
			$cash_lsit1[] = $cash;
		}
		echo json_encode($cash_lsit1);
	}
	
	
	/**
	 * 更多充值
	 * @param int $page
	 */
	function recharge_log_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		//echo $page;exit;
		$parms['page_size'] = 4;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountrecharge_model', 'recharge');
		$this->load->model('Payment_model', 'payment');
		//充值统计
		$resData = $this->recharge->get_accountrecharge_list($parms);
		$data['recharge_list'] 	= $resData['accountrecharge_list'];
		$recharge_status 		= $this->recharge->arrays("account_recharge_status");
		$recharge_type 			= $this->recharge->arrays("account_recharge_type");
		$payment_list 			= $this->payment->get_list();
		$recharge_list = array();
		foreach ($data['recharge_list'] as $recharge){//TODO 信息可选填充
			$recharge['payment'] 		= isset($payment_list[$recharge['payment']]) ? $payment_list[$recharge['payment']]['name'] : '线下充值';
			$recharge['money'] 			= number_format($recharge['money'],2);
			$recharge['fstatus_text'] 	= $recharge_status[$recharge['fstatus']];
			$recharge['add_time'] 		= date('Y-m-d H:i', $recharge['add_time']);
			$recharge_list[] = $recharge;
		}
		echo json_encode($recharge_list);
	}
	
	/**
	 * 更多资金记录
	 * @param int $page
	 */
	function account_log_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 4;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountlog_model', 'accountlog');
		$resData = $this->accountlog->get_accountlog_list($parms);
		$account_log_list = $resData['accountlog_list'];
		$log_type 			= $this->accountlog->arrays("account_type");
		$account_log_list1 = array();
		foreach($account_log_list as $account_log){//TODO 信息可选填充
			$account_log['ftype'] 		= $log_type[$account_log['ftype']];
			$account_log['money'] 		= number_format($account_log['money'],2);
			$account_log['add_time'] 	= date('Y-m-d H:i', $account_log['add_time']);
			$account_log_list1[] 		= $account_log;
		}
		echo json_encode($account_log_list1);
	}
	
	
	// 更多投资明细
	function invite_log_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 4;
		$parms['where']['user_id'] = $user['user_id'];
		/////////////投资明细记录///////////////
		$this->load->model('Borrow_model', 'borrow_tender');
		$resData = $this->borrow_tender->borrow_tender_user_list($parms);
		$invest_list = $resData['tender_list'];
		$borrow_status 	= $this->borrow_tender->arrays("borrow_tender_status");
		
		$invest_lsit1 = array();
		foreach($invest_list as $invest){
			$invest1['account'] 	= number_format($invest['account'],2);
			$invest1['fee'] 	= number_format($invest['fee'],2);
			$invest1['add_time'] = date('Y-m-d H:i', $invest['add_time']);
			$invest1['borrow_id'] = $invest['borrow_id'];
			$invest1['fstatus_text'] = $borrow_status[$invest['tender_fstatus']];
			$invest_lsit1[] = $invest1;
		}
		echo json_encode($invest_lsit1);
	}
		// 更多回款明细
	function collection_log_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 4;
		$parms['order'] =4;
		$parms['select'] = 1;
		$parms['where']['user_id'] = $user['user_id'];
		/////////////回款明细记录///////////////
		$this->load->model('Borrow_model', 'collectionlog');
		$resData = $this->collectionlog->get_user_collection($parms);
		$collection_log_list = $resData['collection_list'];
		//$borrow_status 	= $this->collectionlog->arrays("borrow_tender_status");
	
		$collection_log1 = array();
		foreach($collection_log_list as $collection_log){
			$collection_log1['borrow_id'] = $collection_log['borrow_id'];
			$collection_log1['fstatus']=$collection_log['fstatus'];
			$collection_log1['repay_account'] 	= number_format($collection_log['repay_account'],2);
			$collection_log1['repay_yesaccount'] 	= number_format($collection_log['repay_yesaccount'],2);
			$collection_log1['repay_time'] = date('Y-m-d H:i', $collection_log['repay_time']);
			$collection_log1['repay_yestime'] = date('Y-m-d H:i', $collection_log['repay_yestime']);
			$collection_log_list1[] = $collection_log1;
		}
		echo json_encode($collection_log_list1);
	}
	
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


//****** 20141126 by liub 个人账户中心
class Acenter extends CI_Controller {
    function __construct(){
		parent::__construct();
		
	}
	
	
	// 首页
	function index(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			// 账户资金，提现和充值
	
			// 充值记录查询，页面制定
			
			// 提现记录查询，页面制定
			
			// 资金明细查询，页面制定
			
			// 投资记录查询，页面制定
			$data['tab'] = 2;
			$this->load->view('mobile/accountmsg',$data);
			
		}else{
			header('Location: /mobile/login/index/index.html');
		}
	}
	
	// 充值
	function recharge(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			if (time()>=strtotime('2014-11-26')){
				$ret['msg'] = '线下充值正在开通中，请前往一点投官网使用线上充值';
				$ret['url_title'] = '返回';
				$ret['url_next']="/mobile/acenter.html";//****** by liub 20141126 返回到个人账户中心
				$this->load->view('mobile/msg',$ret);
			}else{
				$this->load->model('User_model', 'user');
				$user = $this->user->get_by_uid($user['user_id']);
				$data['tab'] = 2;
				$this->load->view('mobile/recharge',$user);
			}
		}else{
			header('Location: /mobile/login/index/index.html');
		}
	}
	
	// 提现
	function cash(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			$this->load->model('User_model', 'user');
			$this->load->model('Account_bank_model', 'bank');
			$this->load->model('Account_model', 'account');
			$this->load->model('Accountlog_model', 'accountlog');
			
			$data['user'] = $this->user->get_by_uid($user['user_id']);
			$data['bank_list'] = $this->bank->arrays('var_account_bank');
			$data['account'] = $this->account->get_account($user['user_id']);
			$data['bank'] = $this->bank->get_by_uid($user['user_id']);
			$data['cash_fee'] = $this->accountlog->cash_fee($user['user_id']);
			$data['cash_fee'] = min($data['cash_fee'],$data['account']['use_money']);
			
			if($data['user']['real_status'] != 1){
				$ret['msg'] = '尚未实名认证';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
				return;
			}elseif (!isset($data['bank']['user_id'])){
				$ret['msg'] = '尚未填写银行账户';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
				return;
			}
			$data['tab'] = 2;
			$this->load->view('mobile/cash',$data);
		}else{
			header('Location: /mobile/login/index/index.html');
		}
	}
	
	// 提交提现
	function submit(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			$this->load->model('User_model', 'user');
			$this->load->model('Account_bank_model', 'bank');
			$this->load->model('Account_model', 'account');
			$this->load->model('Accountlog_model', 'accountlog');
			
			$data['user'] = $this->user->get_by_uid($user['user_id']);
			$data['bank_list'] = $this->bank->arrays('var_account_bank');
			$data['account'] = $this->account->get_account($user['user_id']);
			$data['bank'] = $this->bank->get_by_uid($user['user_id']);
			$data['cash_fee'] = $this->accountlog->cash_fee($user['user_id']);
			$data['cash_fee'] = min($data['cash_fee'],$data['account']['use_money']);
			
			if($data['user']['real_status'] != 1){
				$ret['msg'] = '尚未实名认证';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
			}elseif($data['user']['paypassword'] == ''){
				$ret['msg'] = '尚未设置交易密码';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
			}elseif (!isset($data['bank']['user_id'])){
				$ret['msg'] = '尚未填写银行账户';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/mobile/ucenter.html";
				$this->load->view('mobile/msg',$ret);
			}else{
				$paypwd = $this->input->post('paypwd');
				$money  = $this->input->post('money');
				if(!is_numeric($money)){
					$ret['msg'] = '无效的金额';
					$ret['url_title'] = '返回';
					$ret['url_next']="/mobile/cash.html";
					$this->load->view('mobile/msg',$ret);
					return 0;
				}else{
					$money = round($money,2);
					if($money < 100 || $money > 1000000){
						$ret['msg'] = '单笔提现金额超出范围(100-1000000)';
						$ret['url_title'] = '返回';
						$ret['url_next']="/mobile/cash.html";
						$this->load->view('mobile/msg',$ret);
					}elseif(md5(md5($paypwd)) != $data['user']['paypassword']){
						$ret['msg'] = '交易密码不正确';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}elseif ($data['account']['use_money'] < $money){
						$ret['msg'] = '可用余额不足';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}else{
						
						$expMoney = $data['account']['exp_money_12']+$data['account']['exp_money_24'];
						if ($data['account']['use_money']-$money<$expMoney){
							$ret['msg'] = '体验金不能用于提现';
							$ret['url_title'] = '返回';
							$ret['url_next']="/zhs_mobile/cash.html";
							$this->load->view('zhs_mobile/msg',$ret);
						}
						$account_result =  $data['account'];
						
						$time = time();
						$ip = $this->input->ip_address();
						$fee = 0;
						
						$use_money = $account_result['use_money'] - $money;
						$use_money = round($use_money,2);
						//15天之内的充值金额提现需要收手续费 0.01收取
						$dont_moeny = $this->accountlog->donnot_mention_15($user['user_id']);
						$dont_moeny = round($dont_moeny,2);
						//提现:15天之内的金额需要收手续费，按千分之五
						if($data['user']['is_loan']==0 && $use_money < $dont_moeny){
							$cha = $dont_moeny-$use_money;
							$cha = min($cha,$money);
							$fee = sprintf("%.2f", ($cha*0.005*100)/100);
						}
						$this->db->trans_strict(FALSE);
						$this->db->trans_begin();//事务开始
						//添加提现表记录
						$setArr = array(
							'user_id' => $user['user_id'],
							'fstatus' => '0',
							'account' => $data['bank']['account'],
							'bank' => $data['bank']['bank'],
							'branch' => $data['bank']['branch'],
							'province' => $data['bank']['province'],
							'city' => $data['bank']['city'],
							'total' => $money,
							'credited' => $money - $fee,
							'fee' =>$fee,
							'add_time' => $time,
							'addip' => $ip
						);
						$this->load->model('Accountcash_model', 'cash');
						$ret = $this->cash->add($setArr);
						if($ret > 0){
							$log = array(
								'user_id' => $user['user_id'],
								'ftype' => CASH_FROST,
								'money' => $money,
								'total' => $data['account']['total'],
								'use_money' => $data['account']['use_money']-$money,
								'no_use_money' => $data['account']['no_use_money']+$money,
								'collection' => $data['account']['collection'],
								'red_money' => $data['account']['red_money'],
								'to_user' => 0,
								'add_time' => $time,
								'addip' => $ip,
								'remark' => "提现冻结"
							);
							$ret = $this->account->addlog($log);
						}
						if($this->db->trans_status() === TRUE){
							$this->db->trans_commit();
							$ret1['msg'] = '提现申请已提交，请等待审核';
							$ret1['url_title'] = '返回';
							$ret1['url_next']="/mobile/ucenter.html";
							$this->load->view('mobile/msg',$ret1);
						}else{
							$this->db->trans_rollback();
							$ret1['msg'] = '提现失败，请重试';
							$ret1['url_title'] = '返回';
							$ret1['url_next']="/mobile/cash/index.html";
							$this->load->view('mobile/msg',$ret1);
						}
					}
				}
			}
		}else{
			header('Location: /mobile/login/index/index.html');
		}
	}

	
	// 充值记录查询
	function queryrecahrge($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountrecharge_model', 'recharge');
		$this->load->model('Payment_model', 'payment');
		//充值统计
		$resData = $this->recharge->get_accountrecharge_list($parms);
		$data['recharge_list'] = $resData['accountrecharge_list'];
		$recharge_status 		= $this->recharge->arrays("account_recharge_status");
		$payment_list 			= $this->payment->get_list();
		$recharge_list = array();
		foreach ($data['recharge_list'] as $recharge){//TODO 信息可填充
			
			$recharge['payment'] 		= isset($payment_list[$recharge['payment']]) ? $payment_list[$recharge['payment']]['name'] : '线下充值';
			$recharge['money'] 			= number_format($recharge['money'],2);
			$recharge['add_time'] 		= date('Y-m-d H:i',$recharge['add_time']);
			$recharge['fstatus_text'] 	= $recharge_status[$recharge['fstatus']];
			$recharge_list[] = $recharge;
		}
		$data['recharge_list'] = $recharge_list;
		$data['page'] = count($data['recharge_list']);
		//echo count($data['recharge_list']);exit;
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/cz', $data);
	}
	
	// 提现记录查询
	function querycash($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		/////////////提现记录///////////////
		$this->load->model('Accountcash_model', 'cash');
		$resData = $this->cash->get_accountcash_list($parms);
		$cash_list = $resData['accountcash_list'];
		$cash_status 	= $this->cash->arrays("account_cash_status");
		$cash_lsit1 = array();
		foreach($cash_list as $cash){//TODO 信息可填充
			$cash['total'] 	= number_format($cash['total'],2);
			$cash['fee'] 	= number_format($cash['fee'],2);
			$cash['add_time'] = date('Y-m-d H:i', $cash['add_time']);
			$cash['fstatus_text'] = $cash_status[$cash['fstatus']];
			$cash_lsit1[] = $cash;
		}
		$data['cash_list'] = $cash_lsit1;
		
		$data['page'] = count($data['cash_list']);
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/tx', $data);
	}
	
		
	// 投资明细查询
	function  querydetails($page=0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		/////////////投资明细记录///////////////
		$this->load->model('Borrow_model', 'borrow_tender');
		$resData = $this->borrow_tender->borrow_tender_user_list($parms);
		$invest_list = $resData['tender_list'];
		$borrow_status 	= $this->borrow_tender->arrays("borrow_tender_status");
		$invest_lsit1 = array();
		foreach($invest_list as $invest){	//TODO 信息可选填充
			$invest['account'] 	= number_format($invest['account'],2);
			$invest['fee'] 	= number_format($invest['fee'],2);
			$invest['add_time'] = date('Y-m-d H:i', $invest['add_time']);
			$invest['fstatus_text'] = $borrow_status[$invest['tender_fstatus']];
			$invest['borrow_id'] = $invest['borrow_id'];
			$invest_lsit1[] = $invest;
		}
		$data['invest_list'] = $invest_lsit1;
		$data['page'] = count($data['invest_list']);
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/tz', $data);
	}
	
	// 资金明细查询
	function queryinvest($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		////////////////资金使用记录////////////////////////
		$this->load->model('Accountlog_model', 'accountlog');
		$resData = $this->accountlog->get_accountlog_list($parms);
		$account_log_list = $resData['accountlog_list'];
		$log_type 			= $this->accountlog->arrays("account_type");
		$account_log_list1 = array();
		foreach($account_log_list as $account_log){//TODO 信息可填充
			$account_log['ftype'] = $log_type[$account_log['ftype']];
			$invest['money'] 	= number_format($account_log['money'],2);
			$account_log['add_time'] = date('Y-m-d H:i', $account_log['add_time']);
			$account_log_list1[] = $account_log;
		}
		$data['account_log_list'] = $account_log_list1;
		$data['page'] = count($data['account_log_list']);
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/zj', $data);
	}
	// 回款明细查询
	function queryreturn($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['order'] = 4;
		$parms['select'] = 1;
		$parms['where']['user_id'] = $user['user_id'];
		////////////////资金回款记录////////////////////////
		$this->load->model('Borrow_model', 'collectionlog');
		$resData = $this->collectionlog->get_user_collection($parms);
		$collection_log_list = $resData['collection_list'];
		//$log_type 			= $this->collectionlog->arrays("account_type");
		$collection_log_list1 = array();
		foreach($collection_log_list as $collection_log){//TODO 信息可填充
			$collection_log1['borrow_id'] = $collection_log['borrow_id'];
			$collection_log1['fstatus']=$collection_log['fstatus'];
			$collection_log1['repay_account'] 	= number_format($collection_log['repay_account'],2);
			$collection_log1['repay_yesaccount'] 	= number_format($collection_log['repay_yesaccount'],2);
			$collection_log1['repay_yestime'] = date('Y-m-d H:i', $collection_log['repay_yestime']);
			$collection_log1['repay_time'] = date('Y-m-d H:i', $collection_log['repay_time']);
			$collection_log_list1[] = $collection_log1;
		}
		$data['collection_log_list'] = $collection_log_list1;
		$data['page'] = count($data['collection_log_list']);
		$data['tab'] = 2;
		$this->load->view('/zhs_mobile/hk', $data);
	}

	
	
	
   /**
	 * 更多提现
	 * @param int $page
	 */
	function cashed_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 4;
		$parms['where']['user_id'] = $user['user_id'];
		//充值统计
		$this->load->model('Accountcash_model', 'cash');
		$resData = $this->cash->get_accountcash_list($parms);
		$cash_list = $resData['accountcash_list'];
		$cash_status 	= $this->cash->arrays("account_cash_status");
		$cash_lsit1 = array();
		foreach($cash_list as $cash){//TODO 信息可选填充
			$cash['total'] 	= number_format($cash['total'],2);
			$cash['fee'] 	= number_format($cash['fee'],2);
			$cash['add_time'] = date('Y-m-d H:i', $cash['add_time']);
			$cash['fstatus_text'] = $cash_status[$cash['fstatus']];
			$cash_lsit1[] = $cash;
		}
		echo json_encode($cash_lsit1);
	}
	
	
	/**
	 * 更多充值
	 * @param int $page
	 */
	function recharge_log_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		//echo $page;exit;
		$parms['page_size'] = 4;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountrecharge_model', 'recharge');
		$this->load->model('Payment_model', 'payment');
		//充值统计
		$resData = $this->recharge->get_accountrecharge_list($parms);
		$data['recharge_list'] 	= $resData['accountrecharge_list'];
		$recharge_status 		= $this->recharge->arrays("account_recharge_status");
		$recharge_type 			= $this->recharge->arrays("account_recharge_type");
		$payment_list 			= $this->payment->get_list();
		$recharge_list = array();
		foreach ($data['recharge_list'] as $recharge){//TODO 信息可选填充
			$recharge['payment'] 		= isset($payment_list[$recharge['payment']]) ? $payment_list[$recharge['payment']]['name'] : '线下充值';
			$recharge['money'] 			= number_format($recharge['money'],2);
			$recharge['fstatus_text'] 	= $recharge_status[$recharge['fstatus']];
			$recharge['add_time'] 		= date('Y-m-d H:i', $recharge['add_time']);
			$recharge_list[] = $recharge;
		}
		echo json_encode($recharge_list);
	}
	
	/**
	 * 更多资金记录
	 * @param int $page
	 */
	function account_log_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 4;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountlog_model', 'accountlog');
		$resData = $this->accountlog->get_accountlog_list($parms);
		$account_log_list = $resData['accountlog_list'];
		$log_type 			= $this->accountlog->arrays("account_type");
		$account_log_list1 = array();
		foreach($account_log_list as $account_log){//TODO 信息可选填充
			$account_log['ftype'] 		= $log_type[$account_log['ftype']];
			$account_log['money'] 		= number_format($account_log['money'],2);
			$account_log['add_time'] 	= date('Y-m-d H:i', $account_log['add_time']);
			$account_log_list1[] 		= $account_log;
		}
		echo json_encode($account_log_list1);
	}
	
	
	// 更多投资明细
	function invite_log_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 4;
		$parms['where']['user_id'] = $user['user_id'];
		/////////////投资明细记录///////////////
		$this->load->model('Borrow_model', 'borrow_tender');
		$resData = $this->borrow_tender->borrow_tender_user_list($parms);
		$invest_list = $resData['tender_list'];
		$borrow_status 	= $this->borrow_tender->arrays("borrow_tender_status");
		
		$invest_lsit1 = array();
		foreach($invest_list as $invest){
			$invest1['account'] 	= number_format($invest['account'],2);
			$invest1['fee'] 	= number_format($invest['fee'],2);
			$invest1['add_time'] = date('Y-m-d H:i', $invest['add_time']);
			$invest1['borrow_id'] = $invest['borrow_id'];
			$invest1['fstatus_text'] = $borrow_status[$invest['tender_fstatus']];
			$invest_lsit1[] = $invest1;
		}
		echo json_encode($invest_lsit1);
	}
		// 更多回款明细
	function collection_log_more($page = 0){
		$user = $this->session->userdata('rsh_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 4;
		$parms['order'] =4;
		$parms['select'] = 1;
		$parms['where']['user_id'] = $user['user_id'];
		/////////////回款明细记录///////////////
		$this->load->model('Borrow_model', 'collectionlog');
		$resData = $this->collectionlog->get_user_collection($parms);
		$collection_log_list = $resData['collection_list'];
		//$borrow_status 	= $this->collectionlog->arrays("borrow_tender_status");
	
		$collection_log1 = array();
		foreach($collection_log_list as $collection_log){
			$collection_log1['borrow_id'] = $collection_log['borrow_id'];
			$collection_log1['fstatus']=$collection_log['fstatus'];
			$collection_log1['repay_account'] 	= number_format($collection_log['repay_account'],2);
			$collection_log1['repay_yesaccount'] 	= number_format($collection_log['repay_yesaccount'],2);
			$collection_log1['repay_time'] = date('Y-m-d H:i', $collection_log['repay_time']);
			$collection_log1['repay_yestime'] = date('Y-m-d H:i', $collection_log['repay_yestime']);
			$collection_log_list1[] = $collection_log1;
		}
		echo json_encode($collection_log_list1);
	}
	
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}